import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/erp/erpAaOrder/list',
  save='/erp/erpAaOrder/add',
  edit='/erp/erpAaOrder/edit',
  deleteOne = '/erp/erpAaOrder/delete',
  deleteBatch = '/erp/erpAaOrder/deleteBatch',
  importExcel = '/erp/erpAaOrder/importExcel',
  exportXls = '/erp/erpAaOrder/exportXls',
  erpAaOrderProductList = '/erp/erpAaOrder/listErpAaOrderProductByMainId',
  erpAaOrderProductSave='/erp/erpAaOrder/addErpAaOrderProduct',
  erpAaOrderProductEdit='/erp/erpAaOrder/editErpAaOrderProduct',
  erpAaOrderProductDelete = '/erp/erpAaOrder/deleteErpAaOrderProduct',
  erpAaOrderProductDeleteBatch = '/erp/erpAaOrder/deleteBatchErpAaOrderProduct',
  erpAaOrderAddressList = '/erp/erpAaOrder/listErpAaOrderAddressByMainId',
  erpAaOrderAddressSave='/erp/erpAaOrder/addErpAaOrderAddress',
  erpAaOrderAddressEdit='/erp/erpAaOrder/editErpAaOrderAddress',
  erpAaOrderAddressDelete = '/erp/erpAaOrder/deleteErpAaOrderAddress',
  erpAaOrderAddressDeleteBatch = '/erp/erpAaOrder/deleteBatchErpAaOrderAddress',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});

/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}
/**
 * 列表接口
 * @param params
 */
export const erpAaOrderProductList = (params) => {
  if(params['orderId']){
    return defHttp.get({url: Api.erpAaOrderProductList, params});
  }
  return Promise.resolve({});
}


/**
 * 删除单个
 */
export const erpAaOrderProductDelete = (params,handleSuccess) => {
  return defHttp.delete({url: Api.erpAaOrderProductDelete, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const erpAaOrderProductDeleteBatch = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.erpAaOrderProductDeleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const  erpAaOrderProductSaveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.erpAaOrderProductEdit : Api.erpAaOrderProductSave;
  return defHttp.post({url: url, params});
}
/**
 * 导入
 */
export const erpAaOrderProductImportUrl = '/erp/erpAaOrder/importErpAaOrderProduct'

/**
 * 导出
 */
export const erpAaOrderProductExportXlsUrl = '/erp/erpAaOrder/exportErpAaOrderProduct'
/**
 * 列表接口
 * @param params
 */
export const erpAaOrderAddressList = (params) => {
  if(params['orderId']){
    return defHttp.get({url: Api.erpAaOrderAddressList, params});
  }
  return Promise.resolve({});
}


/**
 * 删除单个
 */
export const erpAaOrderAddressDelete = (params,handleSuccess) => {
  return defHttp.delete({url: Api.erpAaOrderAddressDelete, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const erpAaOrderAddressDeleteBatch = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.erpAaOrderAddressDeleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const  erpAaOrderAddressSaveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.erpAaOrderAddressEdit : Api.erpAaOrderAddressSave;
  return defHttp.post({url: url, params});
}
/**
 * 导入
 */
export const erpAaOrderAddressImportUrl = '/erp/erpAaOrder/importErpAaOrderAddress'

/**
 * 导出
 */
export const erpAaOrderAddressExportXlsUrl = '/erp/erpAaOrder/exportErpAaOrderAddress'
